package com.zygh.lz.controller;

import com.alibaba.fastjson.JSONObject;
import com.zygh.lz.entity.Gislocation;
import com.zygh.lz.service.GisLocationService;
import com.zygh.lz.stapprove.*;
import com.zygh.lz.vo.ResultBean;
import com.zygh.lz.vo.ResultBeans;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(tags = "各支队辖区", description = "GisLocationController")
@RestController
public class GisLocationController {

    @Resource
    private GisLocationService gisLocationService;

    @ApiOperation("查询所有辖区")
    @GetMapping(value = "selectGisLocation")
    public ResultBean selectGisLocation(Integer id) {
        return gisLocationService.selectGisLocation(id);

    }


    @ApiOperation("新增辖区")
    @PostMapping(value = "addGisLocation")
    //@SysPcLog(module = "新增辖区",operation = "新增")
    public ResultBean addGisLocation(@RequestBody Gislocation gisLocation) {
        boolean save = gisLocationService.save(gisLocation);
        return ResultUtil.setOK("success", save);
    }

    @ApiOperation("修改辖区")
    @PostMapping(value = "updateGisLocation")
    //@SysPcLog(module = "修改辖区",operation = "修改")
    public ResultBean updateGisLocation(@RequestBody Gislocation gisLocation) {
        return ResultUtil.setOK("success", gisLocationService.updateById(gisLocation));
    }

    @ApiOperation("删除辖区")
    @PostMapping("/deleteGisLocation/{id}")
    //@SysPcLog(module = "删除辖区",operation = "删除")
    public ResultBean deleteGisLocation(@PathVariable("id") Long id) {
        return ResultUtil.setOK("success", gisLocationService.removeById(id));
    }


    @ApiOperation("根据部门id查看本支队辖区")
    @PostMapping("findAreaById")
    @ViLog(logType = "1", module = "根据部门id查看本支队辖区")
    public OutBean findAreaById(@RequestBody(required = false) InBean inBean) {
        JSONObject jsonObject = inBean.convertObj(JSONObject.class);
        ResultBeans resultBeans = gisLocationService.findAreaBySectionId(Integer.parseInt(jsonObject.getString("id")));
        return OutBeanUtil.resSuc(resultBeans, inBean);
    }


//    @GetMapping(value="getGisLocation")
//    public ResultBean getGisLocation(String str){
//      List<>  gisLocationService.selectGisLocation()
//        //1.查询数据库gislocation表的数据
//        //2.根据工具类判断传过来的点是否在某个大队的区域内
//        //3.将数据用json的方式返回
//
//        return  gisLocationService.getGisLocation(str);
//
//    }
//    GraphUtils graphUtils=new GraphUtils();
//    GraphUtils.isPtInPoly(n1.getX() , n1.getY() , ps));


}
